package com.generic.demo3;

/**
 * @ClassName GenericItyMethod
 * @Description TODO
 * @Author Kx
 * @Date 2025/3/26 11:21
 * @Version 1.0
 */
public class GenericItyMethod {
    private Class<?> type;

    /***
     * @author: kx
     * @date: 2025/3/26 11:05
     * @return T 某个类的对象
     * @description: 定义泛型方法实例化某个类的对象
     */
    public <T> T create2() {
        try {
            return (T) type.getDeclaredConstructor().newInstance();
        } catch (Exception e) {
            throw new RuntimeException("无法创建" + type.getName() + "实例");
        }
    }
}
